package base
{
	import com.dusk.util.MathUtil;
	import com.dusk.util.McUtil;
	import com.dusk.util.RandomUtil;
	import com.game.data.constant.FrameRate;
	import com.greensock.TweenMax;
	
	import config.Config;
	
	import flash.display.MovieClip;
	import flash.geom.Point;
	
	public class BaseAura extends MovieClip
	{
		
		public function BaseAura(fromObj:BaseObject, toObj:BaseObject)
		{
			super();
			source = fromObj;
			target = toObj;
			speed = RandomUtil.randSwitch([2,4,6,8]);
		}
		
		public var isReadyToDestroy:Boolean = false;
		protected var source:BaseObject;
		protected var target:BaseObject;
		protected var speed:int;
		protected var power:int;
		private var startCount:int = 20;
		private var _framer:int = 0;
		private var currentState:int = 1;
		
		public function get gc():Config
		{
			return Config.getIns();
		}
		
		public function render(ratio:Number = 1):void
		{
			if (currentState == 3)
			{
				return;
			}
			if (currentState == 1)
			{
				if (startCount > 0)
				{
					--startCount;
				}
				else
				{
					startUp();
				}
			}
			else if (currentState == 2)
			{
				var p:Point = MathUtil.getAngleByTwoPoint(new Point(x,y),new Point(target.getCollideCenter().x, target.getCollideCenter().y));
				x += p.x * speed / ratio;
				y += p.y * speed / ratio;
				speed += 2;
				if (speed > 20)
				{
					speed = 20;
				}
				if(MathUtil.getDist(x,y,target.getCollideCenter().x, target.getCollideCenter().y) <= 15) destroy();
			}
		}
		
		public function renderAnimate():void
		{
			_framer++;
			if (_framer > FrameRate.ANIMATE_FRAME_RATE * 15)
			{
				destroy();
			}
		}
		
		public function setPower(param1:int):void
		{
			power = param1;
		}
		
		public function destroy():void
		{
			if (parent)
			{
				parent.removeChild(this);
			}
			isReadyToDestroy = true;
			source = null;
			target = null;
		}
		
		private function startUp():void
		{
			var upValue:Number = RandomUtil.randInt(30,50);
			TweenMax.to(this, 1, {
				"y": y - upValue, "onCompleteParams": [this], "onComplete": function (param1:BaseAura):void
				{
					param1.startMove();
				}
			});
			currentState = 3;
		}
		
		private function startMove():void
		{
			currentState = 2;
		}
	}
}
